package xyz.hzxiao.handler.transmit;

import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;

/**
 * ws文本信息处理器
 *
 * @author ：FuXx
 * @className : xyz.hzxiao.handler.transmit.WebSocketTextMessageHandler
 * @since ：2025/1/10
 */
public class WebSocketTextMessageHandler extends SimpleChannelInboundHandler<TextWebSocketFrame> {

    /**
     * Is called for each message of type {@code I}.
     *
     * @param ctx the {@link ChannelHandlerContext} which this {@link SimpleChannelInboundHandler}
     *            belongs to
     * @param msg the message to handle
     */
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, TextWebSocketFrame msg) {
        String message = msg.text();
        ctx.writeAndFlush(new TextWebSocketFrame(message.concat(" from server")));
    }
}
